import os
from pathlib import Path
from functools import lru_cache

import yaml

# This module loads the global configuration for the agent server.
GLOBAL_CONFIG = os.getenv('GLOBAL_CONFIG', 'application.yml')

@lru_cache(maxsize=1)
def get_global_config():
    work_dir = Path(__file__).resolve().parent.parent
    config_file_path = os.path.join(work_dir, GLOBAL_CONFIG)

    config = None
    with open(config_file_path, "r", encoding="utf-8") as f:
        config = yaml.safe_load(f)
    return config

